//
//  UIBarButtonItem+Extension.swift
//  Sina_Weibo2
//
//  Created by Elsevier on 16/5/20.
//  Copyright © 2016年 Yang Lu. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    convenience init(imageName:String,target:AnyObject?,action:Selector){
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: imageName + "_hightlighted"), forState: UIControlState.Highlighted)
        button.sizeToFit()
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        self.init(customView:button)
    }
    
    class func creatBarButtonItem(imageName:String) -> UIBarButtonItem {
    
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: imageName + "_hightlighted"), forState: UIControlState.Highlighted)
        button.sizeToFit()
        
        return UIBarButtonItem(customView:button)
    }
}
